//
//  View+NavigationBar.swift
//  SomePasti
//
//  Created by 李永彬 on 2025/10/4.
//

import SwiftUI

// 在 View 中获取安全区域
extension View {
    var topSafeArea: CGFloat {
        return safeAreaInsets.top
    }
    
    var bottomSafeArea: CGFloat {
        return safeAreaInsets.bottom
    }
    
    private var safeAreaInsets: UIEdgeInsets {
        guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
              let window = windowScene.windows.first else {
            return .zero
        }
        return window.safeAreaInsets
    }
    
    func hideKeyboard() {
        UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
    }
}
